package databaseconnector;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBProcessor {
	private Connection connection;
	private PreparedStatement psSecondHand;
	private PreparedStatement psRent;
	private PreparedStatement psAsk;

	public DBProcessor() {
		this.connection = DBUtils.getConnection();
		String getSecondHand = "SELECT * FROM `homeinfo`.`secondhandinfo`";
		String getRent = "SELECT * FROM `homeinfo`.`rentinfo`";
		String getAsk = "SELECT * FROM `homeinfo`.`askinfo` ";
		try {
			psSecondHand = connection.prepareStatement(getSecondHand);
			psRent = connection.prepareStatement(getRent);
			psAsk = connection.prepareStatement(getAsk);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public ResultSet getRent() {
		try {
			return psRent.executeQuery();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;

	}
	public ResultSet getAsk() {
		try {
			return psAsk.executeQuery();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;

	}	public ResultSet getSecondHand() {
		try {
			return psSecondHand.executeQuery();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;

	}
	public void close() {
		try {
			this.connection.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
